#ifndef _TAROT_TAROTDIVINATIONPAGE_H
#define _TAROT_TAROTDIVINATIONPAGE_H

#include <webkit/webkit.h>
#include <amanita/aMath.h>
#include "../Main.h"
#include "../Page.h"
#include "../Profile.h"
#include "TarotDeck.h"
#include "TarotStar.h"
#include "Card.h"



class TarotDivinationPage : public Page {
private:
	struct {
		GtkWidget *webview;
		GtkWidget *table;
	} gtk;

	struct {
		GdkPixbuf *bg;
		GdkPixbuf *info;
		GdkPixbuf *label;
	} image;

	Profile profile;
	TarotDeck deck;					/**< The complete deck of cards. */
	CardSet cards;						/**< The set of cards working with for this divination, it can be all cards or only trumps for example. */
	CardSet tableau;					/**< Cards spread on the table, that is moved to the Star. */
	TarotStar star;					/**< The tarot Star. */
	aVector patterns;
	Card *selected;

	struct {
		bool pressed;
		bool dragged;
		GdkPoint drag;
	} mouse;

	struct {
		cairo_rectangle_int_t dimension;
		int view;
		int spread;
		double scale;
		int nareas;
		cairo_rectangle_int_t areas[10];
	} table;

	static void webview_hover_event_callback(WebKitWebView *webview,gchar *title,gchar *uri,gpointer data);
	static gboolean webview_navigation_decision_event_callback(WebKitWebView *webview,WebKitWebFrame *frame,WebKitNetworkRequest *request,
																	WebKitWebNavigationAction *action,WebKitWebPolicyDecision *decision,gpointer data);
//	static gboolean webview_navigation_event_callback(WebKitWebView *webview,WebKitWebFrame *frame,WebKitNetworkRequest *request,gpointer data);
	static gboolean table_configure_event_callback(GtkWidget *widget,GdkEventConfigure *event,gpointer data);
	static gboolean table_expose_event_callback(GtkWidget *widget,GdkEventExpose *event,gpointer data);
	static gboolean table_mouse_move_event_callback(GtkWidget *widget,GdkEventMotion *event,gpointer data);
	static gboolean table_mouse_press_event_callback(GtkWidget *widget,GdkEventButton *event,gpointer data);
	static gboolean table_mouse_release_event_callback(GtkWidget *widget,GdkEventButton *event,gpointer data);

	void resetTable() { table.scale = 1.0,table.nareas = 0; }
	void calculateScale(int &w,int &h,double sw,double sh);
	int scaleTo(double d) { return aMath::round(d*table.scale); }
	int scaleFrom(double d) { return aMath::round(d/table.scale); }
	cairo_rectangle_int_t &addTableArea(int x,int y,int w,int h);

public:
	static int colors[6];
	static int element_colors[5];

	TarotDivinationPage(Profile *p,const char *d,const char *s,int sp=0);
	~TarotDivinationPage();

	void paint(const cairo_region_t *region=0);
	void repaint(const cairo_rectangle_int_t *rects=0,int nrects=0);

	void arrangeCards(int x,int y,int w,int h);

	int mouseMove(int x,int y,GdkPoint *drag,GdkEventMotion *event);
	int mouseDown(int x,int y,GdkEventButton *event);
	int mouseUp(int x,int y,GdkEventButton *event);

	Card *findCard(int x,int y);
	void selectCard(Card *c,bool unselect_previous=true);
	void starSelected();

	void showText(aString &str);
	void showStarText(TarotStar &s);
	void showCardText(Card &c);
	void writeStarText(aString &str,TarotStar &s);
	void writeCardText(aString &str,Card &c);
};



#endif /* _TAROT_TAROTDIVINATIONPAGE_H */


